package xixirupan.tmgp.tencent.com.vmeim.ui.shopcar.presenter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import xixirupan.tmgp.tencent.com.vmeim.R;
import xixirupan.tmgp.tencent.com.vmeim.config.URLConfig;
import xixirupan.tmgp.tencent.com.vmeim.ui.shopcar.model.RecommendProductsBaen;

/**
 * Created by lenovo on 2016/10/20.
 */

public class ShopcarRecyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private  List<RecommendProductsBaen> lists;
    private LayoutInflater inflater;
    private Context context;
    public ShopcarRecyAdapter(List<RecommendProductsBaen> lists,LayoutInflater inflater,Context context)
    {
        this.context =context;
        this.inflater =inflater;
        this.lists =lists;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_recycler_shopcar, parent, false);
        ViewHolderCar car =new ViewHolderCar(view);


        return car;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
         if (holder instanceof ViewHolderCar)
         {
            long _price = lists.get(position).getVmeiPrice();
             double price = _price / 100;

             ((ViewHolderCar) holder).textView_price.setText("¥"+price);
             ((ViewHolderCar) holder).textView_title.setText(lists.get(position).getName());
             String firstPic = lists.get(position).getFirstPic();
             String url = URLConfig.UrlMain.SHOPCAR_IMGBEFORE+firstPic;

             Glide.with(context).load(url).into(((ViewHolderCar) holder).imageView_product);
         }
    }

    @Override
    public int getItemCount() {
        return lists.size();
    }

    class ViewHolderCar extends RecyclerView.ViewHolder
    {
        ImageView imageView_product;
        TextView textView_title;
        TextView textView_price;

        public ViewHolderCar(View itemView) {
            super(itemView);
            imageView_product = (ImageView) itemView.findViewById(R.id.item_shopcar_imgview);
            textView_title = (TextView) itemView.findViewById(R.id.item_shopcar_title);
            textView_price = (TextView) itemView.findViewById(R.id.item_shopcar_vmeiprice);


        }
    }
}
